<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="银行卡号" prop="bankcardNumber">
        <el-input
          v-model="queryParams.bankcardNumber"
          placeholder="请输入银行卡号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人" prop="userName">
        <el-input
            v-model="queryParams.userName"
            placeholder="请输入申请人姓名"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系方式" prop="phone">
        <el-input
            v-model="queryParams.phone"
            placeholder="请输入联系方式"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="auditStatus">
        <el-select v-model="queryParams.auditStatus" placeholder="请选择审核状态" clearable>
          <el-option
            v-for="dict in user_expert_audit_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="申请类型" prop="walletType">
        <el-select v-model="queryParams.walletType" placeholder="请选择申请人类型" clearable>
          <el-option
              v-for="dict in wallet_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="提现类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择提现类型" clearable>
          <el-option
              v-for="dict in withdrawal_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['pay:walletAudit:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="walletAuditList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="申请人" align="center" prop="userName" />
      <el-table-column label="申请人类型" align="center" prop="walletType">
        <template #default="scope">
          <dict-tag :options="wallet_type" :value="scope.row.walletType"/>
        </template>
      </el-table-column>
      <el-table-column label="联系方式" width="150" align="center" prop="phone" />
      <el-table-column label="提现金额" align="center" prop="balance" />
      <el-table-column label="提现类型" align="center" prop="type">
        <template #default="scope">
          <dict-tag :options="withdrawal_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="支付宝账号" width="150" align="center" prop="alipayAccount" />
      <el-table-column label="收款码" align="center" prop="paymentCode">
        <template #default="scope">
          <image-preview :src="scope.row.paymentCode" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="银行卡号" width="250" align="center" prop="bankcardNumber" />
      <el-table-column label="银行卡手机号" width="150" align="center" prop="bankcardPhone"/>
      <el-table-column label="审核节点" align="center" prop="stepName"/>
      <el-table-column label="审核状态" align="center" prop="auditStatus">
        <template #default="scope">
          <dict-tag :options="user_expert_audit_status" :value="scope.row.auditStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="250" class-name="small-padding fixed-width" fixed="right">
        <template #default="scope">
          <el-button link type="primary" icon="View" @click="handleView(scope.row, scope.index)" v-hasPermi="['pay:walletAudit:query']">详情</el-button>
          <el-button v-if="scope.row.auditStatus === '00' && scope.row.isAudit === 'Y'" link type="primary" icon="CircleCheck" @click="handleExamine(scope.row.id,'01')" v-hasPermi="['pay:walletAudit:edit']">通过</el-button>
          <el-button v-if="scope.row.auditStatus === '00' && scope.row.isAudit === 'Y'" link type="primary" icon="CircleClose" @click="handleExamine(scope.row.id,'02')" v-hasPermi="['pay:walletAudit:edit']">拒绝</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改提现审核对话框 -->
    <el-dialog title="审核详情" v-model="open" width="700px" append-to-body>
      <el-form :model="form" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="申请人：">{{ form.userName }}</el-form-item>
            <el-form-item
                label="申请金额："
            >{{ form.balance }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="类型：">
              <dict-tag :options="wallet_type" :value="form.walletType"/>
            </el-form-item>
            <el-form-item label="联系方式：">{{ form.phone }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="提现类型：">
              <dict-tag :options="withdrawal_type" :value="form.type"/>
            </el-form-item>
            <el-form-item label="联系方式：">{{ form.phone }}</el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.type === '2'">
            <el-form-item label="支付宝号：">{{ form.alipayAccount }}</el-form-item>
          </el-col>
<!--          <el-col :span="12" v-if="form.type === '2' || form.type === '3'">-->
<!--            <el-form-item label="收款码：" prop="paymentCode">-->
<!--              <image-preview :src="form.paymentCode" :width="150" :height="150"/>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
          <el-col :span="12" v-if="form.type === '1'">
            <el-form-item label="银行卡号：">{{ form.bankcardNumber }}</el-form-item>
            <el-form-item label="手机号：">{{ form.bankcardPhone }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审核状态：">
              <dict-tag :options="user_expert_audit_status" :value="form.auditStatus"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="审核节点：">
              <div style="height: 300px">
                <el-steps :space="400" style="width: 400px"
                          :active="(form.auditStatus === '00')?form.stepType-1:form.stepType"
                          :finish-status="finishStatus">
                  <el-step v-for="step in form.walletAuditStep" :title="step.stepName"/>
                </el-steps>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button v-if="form.auditStatus === '00'" type="primary" @click="handleExamine(form.id,'01')">通 过</el-button>
          <el-button v-if="form.auditStatus === '00'" type="deleted" @click="handleExamine(form.id,'02')">拒 绝</el-button>
          <el-button @click="open = false">关 闭</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="WalletAudit">
import {
  listWalletAudit,
  getWalletAudit,
  delWalletAudit,
  updateWalletAuditExamine,
  submitWalletAuditExamine
} from "@/api/pay/walletAudit";
import {getTyEvaluation} from "@/api/pay/tyEvaluation";

const { proxy } = getCurrentInstance();
const { user_expert_audit_status,wallet_type,withdrawal_type } = proxy.useDict('user_expert_audit_status','wallet_type','withdrawal_type');

const walletAuditList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
let finishStatus = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    bankcardNumber: undefined,
    bankcardPhone: undefined,
    auditStatus: undefined,
  },
  rules: {

  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询提现审核列表 */
function getList() {
  loading.value = true;
  listWalletAudit(queryParams.value).then(response => {
    walletAuditList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: undefined,
    walletId: undefined,
    balance: undefined,
    type: undefined,
    alipayAccount: undefined,
    paymentCode: undefined,
    bankcardNumber: undefined,
    bankcardPhone: undefined,
    auditStatus: undefined,
    auditorId: undefined,
    createTime: undefined,
    updateTime: undefined
  };
  proxy.resetForm("walletAuditRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加提现审核";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getWalletAudit(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改提现审核";
  });
}

/** 提交按钮 */
function handleExamine(id,auditStatus) {
  let text = auditStatus === '01' ? '通过' : '拒绝'
  proxy.$modal.confirm('是否'+text+'提现审核').then(function() {
    form.value.id = id;
    form.value.auditStatus = auditStatus;
    updateWalletAuditExamine(form.value).then(response => {
      open.value = false;
      getList();
      proxy.$modal.msgSuccess("审核成功");
    });
  }).catch(() => {
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除该数据项？').then(function() {
    return delWalletAudit(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('pay/walletAudit/export', {
    ...queryParams.value
  }, `walletAudit_${new Date().getTime()}.xlsx`)
}

/** 详细按钮操作 */
function handleView(row) {
  const _id = row.id
  getWalletAudit(_id).then(response => {
    form.value = response.data;
    if (form.value.auditStatus === '01' || form.value.auditStatus === '2'){
      finishStatus.value = 'success';
    }
    open.value = true;
  });
}

getList();
</script>
